import static play.test.Helpers.fakeApplication;
import static play.test.Helpers.running;

import java.util.Date;

import org.junit.Test;

import models.WmWallet;
import models.Account.ChineseProvince;
import models.Account.FinancialInstitution;

import play.libs.F.Function0;
import prefix.integration.wm.AbstractWalletManager;
import prefix.integration.wm.WMProcessor;
import prefix.util.JPAUtil;
import processor.AccountProcessor;
import processor.ActorProcessor;
import repository.AbstractRepository;
import repository.ActorRepository;
import service.AccountService;
import service.ActorService;
import service.impl.AccountServiceImpl;

public class CreateSystemActor {
    @Test
    public void startTest() {
        running(fakeApplication(), new Runnable() {
            @Override
            public void run() {
                create();
            }
        });
    }

    public void create() {
        try {
            createORIGINATION_FEE_ACCOUNT_W2();
            createBORROWER_MGMT_FEE_W3();
            createSERVICE_FEE_ACCOUNT_W4();
            createCUSTOMER_WITHDRAW_WALLET_W5();
            createCUSTOMER_FUNDS_WALLET_W6();
            createREFERALS_BONUS_WALLET_W7();
            createPUSH_FUNDS_WALLET_W8();
        } catch (Throwable t) {
            t.printStackTrace();
        }

    }

    private void createORIGINATION_FEE_ACCOUNT_W2() throws Throwable {
        actureCreate(2, "ORIGINATION_FEE_ACCOUNT");
    }

    private void createBORROWER_MGMT_FEE_W3() throws Throwable {
        actureCreate(3, "BORROWER_MGMT_FEE");
    }

    private void createSERVICE_FEE_ACCOUNT_W4() throws Throwable {
        actureCreate(4, "SERVICE_FEE_ACCOUNT");
    }

    private void createCUSTOMER_WITHDRAW_WALLET_W5() throws Throwable {
        actureCreate(5, "CUSTOMER_WITHDRAW_WALLET");
    }

    private void createCUSTOMER_FUNDS_WALLET_W6() throws Throwable {
        actureCreate(6, "CUSTOMER_FUNDS_WALLET");
    }

    private void createREFERALS_BONUS_WALLET_W7() throws Throwable {
        actureCreate(7, "REFERALS_BONUS_WALLET");
    }

    private void createPUSH_FUNDS_WALLET_W8() throws Throwable {
        actureCreate(8, "PUSH_FUNDS_WALLET");
    }

    private void actureCreate(final Integer aid, String name) throws Throwable {

        ActorService actor = ActorRepository.getActorServiceById(aid);
        JPAUtil.closeEM();
        AccountService account = new AccountServiceImpl();
        AccountProcessor accountProcessor = account.getProcessor();
        accountProcessor.addNewBankAccount(actor, ChineseProvince.Henan, "郑州", FinancialInstitution.BOC, "123");
        AbstractWalletManager wm = AbstractWalletManager.getInstance();
        wm.createWallet(aid, name, WmWallet.Type.SYSTEM);
    }
}
